<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8" />
    <title>智慧社区-物业管理</title>

    <meta name="description" content="Dashboard" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/resource/assets/img/favicon.png" type="image/x-icon">

    <!--Basic Styles-->
    <link href="${pageContext.request.contextPath}/resource/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link href="${pageContext.request.contextPath}/resource/assets/css/font-awesome.min.css" rel="stylesheet" />

    <!--Beyond styles-->
    <link href="${pageContext.request.contextPath}/resource/assets/css/beyond.min.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath}/resource/assets/css/animate.min.css" rel="stylesheet" />
<script src="${pageContext.request.contextPath}/resource/assets/js/skins.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/ckeditor/ckeditor.js"></script>
</head>
<body>
<%@include file="../header.jsp" %>
	<!-- Main Container -->
    <div class="main-container container-fluid">
        <!-- Page Container -->
        <div class="page-container">
            <!-- Page Sidebar -->
            <%@include file="../nav.jsp" %><!-- /Page Sidebar -->
            <!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb" style="margin-top: 8px;">
                        <li>
                            <i class="fa fa-home"></i>
                            <a href="#">首页</a>
                        </li>
                        <li><a href="#">公告管理</a></li>
                        <li class="active">发布公告</li>
                    </ul>
                </div><!-- /Page Breadcrumb -->
                <!-- Page Header -->
                <div class="page-header position-relative">
                    <div class="header-title" style="margin-top: 2px;">
                        <h1>
                            发布公告
                        </h1>
                    </div><!--Header Buttons-->
                    <div class="header-buttons">
                        <a class="sidebar-toggler" href="#">
                            <i class="fa fa-arrows-h"></i>
                        </a>
                        <a class="refresh" id="refresh-toggler" href="">
                            <i class="glyphicon glyphicon-refresh"></i>
                        </a>
                        <a class="fullscreen" id="fullscreen-toggler" href="#">
                            <i class="glyphicon glyphicon-fullscreen"></i>
                        </a>
                    </div><!--Header Buttons End-->
                </div><!-- /Page Header -->
                <!-- Page Body -->
                <div class="page-body">
                	<div class="row">
	                	<div class="col-lg-6 col-sm-6 col-xs-12">
	                		<div class="widget">
                                        <div class="widget-header bordered-bottom bordered-palegreen">
                                            <span class="widget-caption">发布公告</span>
                                        </div>
                                        <div class="widget-body">
                                           <div id="registration-form">
                                                        <form role="form">
                                                            <div class="form-title">
                                                            	公告信息
                                                            </div>
                                                            	<div class="form-group">
                                                                        <span class="input-icon icon-right">
                                                                            <input type="text" class="form-control" placeholder="所属小区" value="${loginUser.loginVillage.name}" disabled>
                                                                            <i class="glyphicon glyphicon-globe circular"></i>
                                                                       </span>
                                                              	</div>
                                                            <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="subject" type="text" class="form-control"  placeholder="公告主题" value="${announce.subject }">
                                                                    <i class="glyphicon glyphicon-user circular"></i>
                                                                </span>
                                                            </div>
                                                            
                                                            <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                	<textarea class="form-control" rows="10" id="content" placeholder="公告描述"></textarea>
                                                                     <script>CKEDITOR.replace( 'content',{height:'300px',filebrowserUploadUrl:'${pageContext.request.contextPath}/ckeditorUpload'} );</script>
                                                         		</span>
                                                            </div>
                                                            <div class="form-group">
									                                            <div class="controls">
									                                                <div class="input-group">
									                                                    <input type="text" class="form-control" id="reservation" placeholder="公告有效期" />
									                                                    <span class="input-group-addon">
									                                                        <i class="fa fa-calendar"></i>
									                                                    </span>
									                                                </div>
									                                            </div>
                                                            </div>
                                                            <div class="form-group">
										                      <label for="fileUpload">上传图片(单选)</label>
										                      <input type="file" id="fileUpload" name="upload">
										                      <p class="help-block">给此条小区公告添加列表显示图片.</p>
                    										</div>
                                                            <hr class="wide" />
                                                            <div class="row" style="text-align: right;margin-right: 10px;">
                                                            	<button type="button" class="btn btn-blue" onclick="save()"> 保 存 </button>
                                                            </div>
                                                            
                                                        </form>
                                                    </div> 
                                        </div>
                                    </div>
	                	</div>
                	
                    </div>
                </div><!-- /Page Body -->
             </div><!-- /Page Content -->
     	</div><!-- /Page Container -->
     </div><!-- /Main Container -->
     	<script src="${pageContext.request.contextPath}/resource/assets/js/jquery-2.0.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/resource/assets/js/bootstrap.min.js"></script>

    <!--Beyond Scripts-->
    <script src="${pageContext.request.contextPath}/resource/assets/js/beyond.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resource/assets/js/ajaxfileupload.js"></script>
    <script src="${pageContext.request.contextPath}/resource/assets/js/datetime/moment.js"></script>
    <script src="${pageContext.request.contextPath}/resource/assets/js/datetime/daterangepicker.js"></script>
    <script type="text/javascript">
    	$('.loading-container').hide();
    	$('#menu_announce').addClass("active open");
    	$('#menu_announceadd').addClass("active");
    	
    	 var start = "${announce.beginAt}";
    	    var end = "${announce.endAt}";
    	    var objectId = "${announce.objectId}";
    	    var editContent = "${announce.content}";
        	
        	$(function(){
        		CKEDITOR.instances.content.setData(decodeURIComponent(editContent));
        	});
    	    if(start != ""){
    			var startAt = unixToDate(start);
    			var endAt = unixToDate(end);
    			var date = startAt + " - " + endAt;
    			$('#reservation').val(date);
    			
    		}
    	 
    	 $('#reservation').daterangepicker({
 		}, function(startDate, endDate) {
 			start = startDate+"";
 			end = endDate+"";
 		});
    	function save(){
    		
    		var subject = $('#subject').val();
    		var content = CKEDITOR.instances.content.getData();
    		var contentForMachine = CKEDITOR.instances.content.document.getBody().getText();
    		if ($.trim(subject) == "" || $.trim(content) == "" || start == "" || end == "") {
    			alert("请完善公告信息后再提交保存");
    			return;
    		}
    		var encodeContent = encodeURIComponent(content);
    		$('.loading-container').show();
    		$.ajaxFileUpload({
		        url: '${pageContext.request.contextPath}/announce_add',
		        secureuri: false,
		        data: {objectId:objectId,subject:subject,content:encodeContent,beginAt:start,endAt:end,contentForMachine:contentForMachine},
		        fileElementId: 'fileUpload',
		        dataType: 'json',
		        success: function (data) {
		        	$('.loading-container').hide();
		        	alert("公告信息保存成功");
	        		$('#subject').val("");
		        	$('#content').val("");
		        	$('#reservation').val("");
		        	start = "";
					end = "";
					CKEDITOR.instances.content.setData("");
		        },
		        error: function (data) {
		        	alert("error msg:"+data.responseText);
		        }
		    });
    	}
    </script>
</body>
</html>